import {getCompanyInfoList, getCompanyVo} from "@/api/company";

const state = {
    list: [],
    total: 0
}

const mutations = {

    SET_COMPANYINFOLIST: (state, data) => {
        state.list = data.records
        state.total = data.total
    },
}

const actions = {

    getCompanyInfoList({ commit }, data) {
        return new Promise((resolve, reject) => {
            getCompanyInfoList(data).then((resp) => {
                const { data } = resp.data
                commit('SET_COMPANYINFOLIST', data)
                resolve(data)
            }).catch(error => reject(error))
        })
    },

    getCompanyVo({ commit }, company) {
        return new Promise((resolve, reject) => {
            getCompanyVo(company).then((resp) => {
                if (resp.data.code === 1) {
                    resolve(resp.data.data)
                } else if (resp.data.code === 0) {
                    reject(resp.data.msg)
                }
                reject("获取信息失败")
            }).catch(error => reject(error))
        })
    },
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
